// pages/detail/reference/reference.ts
import { getPublicPaddingTop } from '../../../utils/page'
import { getUserInformation, collectAdd, handAdd } from '../../../utils/controller'
import {
  ATTR,
  DEGREE,
  ANNUAL_INCOME,
  IS_CAR,
  IS_CERT,
  IS_COHABIT,
  IS_FEAST,
  IS_HOUSE,
  IS_MARRY,
  IS_MATE,
  CHILD_PLAN,
  RELATIVES_PLAN,
  MARRY_PLAN,
} from '../../../config/index'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    paddingTop: getPublicPaddingTop(),

    userInfo: {},
    ATTR,
    DEGREE,
    ANNUAL_INCOME,
    IS_CAR,
    IS_CERT,
    IS_COHABIT,
    IS_FEAST,
    IS_HOUSE,
    IS_MARRY,
    IS_MATE,
    CHILD_PLAN,
    RELATIVES_PLAN,
    MARRY_PLAN,
    user_id:'',
    viewWechatID:true
  },
  goBack(){
    wx.switchTab({
      url:"/pages/home/home"
   })
  },
  // 点击查看微信
  viewWechat(){
    let token = wx.getStorageSync('token')
    if(!token){
      wx.switchTab({
        url:'/pages/personal/personal'
      })
      return
    }
    // 判断是否是会员
    let userInfo:any = wx.getStorageSync('userInfo')
    if(userInfo){
      userInfo = JSON.parse(userInfo);
    }
    console.log(userInfo.is_member);
    if(userInfo.is_member != 1){
      
      wx.showModal({
        title: '',
         content: '成为会员后可查看微信哦',
         showCancel: true,//是否显示取消按钮
         cancelText:"在想想",//默认是“取消”
        //  cancelColor:'skyblue',//取消文字的颜色
         confirmText:"去升级",//默认是“确定”
         confirmColor: 'skyblue',//确定文字的颜色
         success: res => {
            if (res.cancel) {
               //点击取消,默认隐藏弹框
            } else {
               //点击确定 
              wx.navigateTo({
                url:'/pages/vip/vip'
              })
            }
         },
         fail: function (res) { },//接口调用失败的回调函数 
         
      })
      return
    }
    this.setData({
      viewWechatID:false
    })
  },
  share(){
    wx.showShareMenu({

      withShareTicket: true,
      
      menus: ['shareAppMessage', 'shareTimeline']
      
      })
  },
  //用户点击右上角转发到朋友圈
  onShareTimeline(){
  },
  // 复制微信号功能函数
  useCopy() {
    const _this = this
    wx.setClipboardData({
      data: _this.data.userInfo.wechat,
      success(res) {
        wx.showToast({
              icon:'success',
              title:"复制成功",
              duration:2000
            })
        // wx.getClipboardData({
        //   success(res) {
        //     // wx.showToast({
        //     //   icon:'success',
        //     //   title:"复制成功",
        //     //   duration:2000
        //     // })
        //     console.log(res.data) // data
        //   },
        // })
      },
    })
    this.handAdd()
  },

  // 收藏功能函数
  async useCollect() {
    let res:any = await collectAdd(this.data.userInfo.id)
    let is_collect = this.data.userInfo.is_collect
    if(res.code == 10000){

      // wx.showToast({icon:'none', title:res.msg})
      await this.userInfo(this.data.userInfo.id)
      if(is_collect === 1){
        wx.showToast({icon:'none', title:'取消收藏'})
      }else{
        wx.showToast({icon:'none', title:'收藏成功'})
      }
    }
    
  },
  async handAdd(){
    let userInfo:any = wx.getStorageSync('userInfo')
    if(userInfo){
      userInfo = JSON.parse(userInfo);
      let res:any = await handAdd({to_user_id: userInfo.id})
      
    }
    
  },
  userInfo(id){
    const _this = this
    getUserInformation(id)
      .then((result) => {
        console.log('用户信息', result)
        _this.setData({ userInfo: result })
      })
      .catch((err) => {
        console.log('获取用户信息报错', err)
      })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const id = +options.id
    this.setData({user_id:id})
    this.userInfo(id)
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: this.data.userInfo.self_info || 'L找G,颜值不差，期望合适的对象',
      path: '/pages/detail/reference/reference?id=' + this.data.user_id,
      // imageUrl: 'https://admin.slsxh.com/upload/20240529/LTth19FeEcC979f3e0f82c5fc9df85e6d6104d35e34d.png'
    }
  },
})
